﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using caufingHealth.Forms;
namespace caufingHealth
{
    /// <summary>
    /// The Parent form that will allow for various forms to interact
    /// with the user each for a different function.
    /// <Author>Aaron C. Schwan, John Osborne, Ahmal Jones</Author>
    /// </summary>
    public partial class CaufingHealth : Form
    {
        private int childFormNumber = 0;

        private Imanager Manager = new HealthManager();


        public CaufingHealth()
        {
            caufingHealth.Forms.LoginForm loginForm = new caufingHealth.Forms.LoginForm(caufingHealth.Forms.LoginForm.ENCRYPTION_LEVEL.Sha512);

            if (loginForm.ShowDialog() == DialogResult.OK)
            {
                if (!Manager.Login(loginForm.UserName, loginForm.SecurePassword))
                    this.Close();
            }
            else
            {
                this.Close();
            }

            InitializeComponent();
            if (Manager.isAdmin())
                AdminMenu.Enabled = true;
            else
                AdminMenu.Enabled = false;
        }

        private void ShowNewForm(object sender, EventArgs e)
        {

        }

        private void OpenFile(object sender, EventArgs e)
        {

        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void file_patient_Click(object sender, EventArgs e)
        {
            SearchForm patientSearch = new SearchForm();
            PatientInformation.PatientRecord record = new PatientInformation.PatientRecord();
            
            if (patientSearch.ShowDialog(this) == DialogResult.OK)
            {
                switch (patientSearch.CurrentMode)
                {
                    case SearchForm.SEARCH_MODES.DOB:
                        record = Manager.SearchForPatientRecords(patientSearch.DateOfBirth);
                        break;
                    case SearchForm.SEARCH_MODES.FIRST_AND_LAST:
                        record = Manager.SearchForPatientRecords(patientSearch.FirstName, patientSearch.LastName);
                        break;
                    case SearchForm.SEARCH_MODES.LAST_AND_DOB:
                        record = Manager.SearchForPatientRecords( patientSearch.LastName, patientSearch.DateOfBirth);
                        break;
                }
                if (record == null)
                    MessageBox.Show("No Records found");
                else
                {

                    PatientForm patient = new PatientForm(record, Manager);
                    patient.MdiParent = this;
                    patient.Show();
                }
            }
        }

        private void toolStripSeparator4_Click(object sender, EventArgs e)
        {

        }

        private void file_RegisterPatient_Click(object sender, EventArgs e)
        {
            PatientForm patient = new PatientForm(Manager);
            patient.MdiParent = this;
            patient.Show();
        }

        private void RunQueryMenuItem_Click(object sender, EventArgs e)
        {
            AdminForm admin = new AdminForm(Manager, this);
            admin.Show();
        }
    }
}
